<?php
//twitterupdate.php
/**
* @file
*
*/
//$mensagem = "Tenstendo Acento áção ões";
//$s_access_token = '78194376-1ZhHfBp49SkG0GuHVSRmuEBMoGiqyri84tfbYEvIN';
//$s_access_token_secret = 'JnSjzqhepdvXNUnDwf6NUjubmUl7LV5ok9D2y2cbU';

$mensagem = @$_GET['mensagem'];
$s_access_token = @$_GET['s_access_token'];
$s_access_token_secret = @$_GET['s_access_token_secret'];

if($mensagem <> "" && $s_access_token <> "" && $s_access_token_secret <> ""){
	
	/* Load required lib files. */
	session_start();
	require_once('twitteroauth/twitteroauth.php');
	require_once('config.php');
	
	//find the following values in the Access Tokens tab in your twitter.com application control panel
	$_SESSION['access_token'] = $s_access_token; // store session data
	$_SESSION['oauth_token_secret'] = $s_access_token_secret; // store session data
	
	
	
	/* If access tokens are not available redirect to connect page. */
	if (empty($_SESSION['access_token']) ||
	empty($_SESSION['access_token']['oauth_token']) ||
	empty($_SESSION['access_token']['oauth_token_secret'])) {
	header('Location: ./clearsessions.php');
	}
	/* Get user access tokens out of the session. */
	$access_token = $_SESSION['access_token'];
	
	/* Create a TwitterOauth object with consumer/user tokens. */
	
	//the following are already defined and may stay as they appear here
	function getConnectionWithAccessToken($oauth_token, $oauth_token_secret) {
	$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,
	$oauth_token, $oauth_token_secret);
	return $connection;
	}
	
	
	//replace the following with your Access Token and Access Token Secret
	$connection = getConnectionWithAccessToken($s_access_token, $s_access_token_secret);
	
	/* Get logged in user. */
	$user = $connection->get('account/verify_credentials');
	
	$active = TRUE;
	
	
	function twitteroauth_row($method, $response, $http_code, $parameters = '') {
	
	if (!is_string($response)) {
	$response = print_r($response, TRUE);
	}
	if (!is_string($parameters)) {
	$parameters = print_r($parameters, TRUE);
	}
	
	
	}
	
	
	
	/* statuses/update */
	//replace YOUR STATUS UPDATE HERE MUST BE UNIQUE with your current status update.
	$parameters = array('status' => $mensagem);
	$status = $connection->post('statuses/update', $parameters);
	twitteroauth_row('statuses/update', $status, $connection->http_code,
	$parameters);
	 
	
	//uncomment the following for testing
	//print_r($status);
	
}

$retorno = @$_GET['retorno'];
header("Location: $retorno");
?>
